package com.neuedu.his.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.his.common.CommonResult;
import com.neuedu.his.entity.Role;
import com.neuedu.his.service.IRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author 金山
 * @since 2021-04-09
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    IRoleService roleService;


    /**
     * http://127.0.0.1:80/his/role/page
     * @param page
     * @param role
     * @return
     */
    @GetMapping("/page")
    CommonResult  page(Page page, Role role){

        QueryWrapper queryWrapper = new QueryWrapper();
        if(role!= null && StringUtils.isNotEmpty(role.getRoleName())){
            queryWrapper.like("role_name",role.getRoleName());
        }
        return CommonResult.success(roleService.page(page,queryWrapper));
    }


    @PostMapping("/save")
    CommonResult  save( Role role){
        return CommonResult.success(roleService.saveOrUpdate(role));
    }

    @PostMapping("/del")
    CommonResult  del(Integer id){
        return CommonResult.success(roleService.removeById(id));
    }


    @PostMapping("/delByIds")
    CommonResult  delByIds(Integer[] id){
        return CommonResult.success(roleService.removeByIds(Arrays.asList(id)));
    }
}
